package org.example.system.controller;

import lombok.AllArgsConstructor;
import org.example.common.base.domain.UserDto;
import org.example.common.base.util.web.AjaxResult;
import org.example.system.entity.SysUser;
import org.example.system.service.ISysUserService;
import org.example.system.service.impl.SysPermissionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @version 1.0.0
 * @className: SysAdminController
 * @description: 登录接口
 * @author: LiJunYi
 * @create: 2023/4/6 9:41
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin")
public class SysAdminController {

    private final ISysUserService userService;

    private final SysPermissionService permissionService;

    /**
     * 登录
     *
     * @param user 用户
     * @return {@link AjaxResult}
     */
    @PostMapping("/login")
    public AjaxResult login(@Validated @RequestBody SysUser user) {
        return userService.login(user.getUsername(),user.getPassword());
    }

    /**
     * 加载用户用户名
     *
     * @param username 用户名
     * @return {@link UserDto}
     */
    @GetMapping("/loadByUsername")
    public UserDto loadUserByUsername(@RequestParam String username)
    {
        return userService.loadUserByUsername(username);
    }
}
